status: Add `soft-reboot-target` to JSON
authorColin Walters <walters@verbum.org>
Thu, 26 Jun 2025 21:57:58 +0000 (17:57 -0400)
committerColin Walters <walters@verbum.org>
Thu, 26 Jun 2025 21:57:58 +0000 (17:57 -0400)
It's there in the human readable status.

And update the soft-reboot test suite to assert things via
JSON since it's *way* cleaner.

src/ostree/ot-admin-builtin-status.c
tests/kolainst/data-shared/libinsttest.sh
tests/kolainst/destructive/soft-reboot.sh

index 2053b7ee6a4dabd0640de525aefb6381c8a00be5..b84fbba2d33d52b78c251462a77d2bf83610ac33 100644 (file)
@@ -208,6 +208,8 @@ deployment_write_json (OstreeSysroot *sysroot, OstreeRepo *repo, OstreeDeploymen
   ul_jsonwrt_value_boolean (jo, "rollback", is_rollback);
   ul_jsonwrt_value_boolean (jo, "finalization-locked",
                             ostree_deployment_is_finalization_locked (deployment));
+  ul_jsonwrt_value_boolean (jo, "soft-reboot-target",
+                            ostree_deployment_is_soft_reboot_target (deployment));
   ul_jsonwrt_value_boolean (jo, "staged", ostree_deployment_is_staged (deployment));
   ul_jsonwrt_value_boolean (jo, "pinned", ostree_deployment_is_pinned (deployment));
   OstreeDeploymentUnlockedState unlocked = ostree_deployment_get_unlocked (deployment);
index abfcdb8e6b4311b076e4dcf17a26ffe91fb35ed6..0e35f2ce13af99050b9f38d3b094babb2fcb6a5e 100644 (file)
@@ -79,3 +79,24 @@ rpmostree_query_json() {
 }
 host_commit=$(rpmostree_query_json '.deployments[0].checksum')
 host_osname=$(rpmostree_query_json '.deployments[0].osname')
+
+# $1  - json file
+# $2+ - assertions
+assert_jq() {
+    f=$1; shift
+    for expression in "$@"; do
+        if ! jq -e "${expression}" >/dev/null < $f; then
+            jq . < $f | sed -e 's/^/# /' >&2
+            echo 1>&2 "${expression} failed to match $f"
+            exit 1
+        fi
+    done
+}
+
+# Assert that ostree admin status --json matches the provided jq predicates.
+assert_status_jq() {
+    local t=$(mktemp --suffix=.json)
+    ostree admin status --json > $t
+    assert_jq $t "$@"
+    rm $t
+}
index 25624c035c41a5ddb9cbe3863fb7ff9b2552efcf..8436525893ea7569ab6f9144fcb6287baa04ac2b 100755 (executable)
@@ -12,6 +12,7 @@ case "${AUTOPKGTEST_REBOOT_MARK:-}" in
   systemctl mask --now zincati
 
   assert_streq $(systemctl show -P SoftRebootsCount) 0
+  assert_status_jq '.deployments[0].pending | not' '.deployments[0].["soft-reboot-target"] | not'
 
   # Create a synthetic commit for upgrade
   cd /ostree/repo/tmp
@@ -21,14 +22,21 @@ case "${AUTOPKGTEST_REBOOT_MARK:-}" in
   newcommit=$(ostree rev-parse soft-reboot-test)
   # Deploy the new commit normally first
   ostree admin deploy --stage soft-reboot-test
-  
+
+  assert_status_jq '.deployments[0].pending' '.deployments[0].["soft-reboot-target"] | not'
+
   # Test prepare-soft-reboot command
   echo "Testing prepare-soft-reboot..."
   ostree admin prepare-soft-reboot 0
-  
+
+  # Test human readable format
   ostree admin status > status.txt
   assert_file_has_content_literal status.txt '(pending) (soft-reboot)'
 
+  # And via JSON
+  assert_status_jq '.deployments[0].pending' '.deployments[0].["soft-reboot-target"]'
+
+  # Verify the internal state file
   test -f /run/ostree/nextroot-booted
   
   /tmp/autopkgtest-soft-reboot "2"
@@ -45,6 +53,8 @@ case "${AUTOPKGTEST_REBOOT_MARK:-}" in
     exit 1
   fi
 
+  assert_status_jq '.deployments[0].booted' '.deployments[0].["soft-reboot-target"] | not'
+
   test -f /etc/new-file-for-soft-reboot
   test -f /usr/share/test-file-for-soft-reboot